package com.imooc.trading_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.imooc.trading_system.mapper.UserMapper;
import com.imooc.trading_system.model.RouterDO;
import com.imooc.trading_system.mapper.RouterMapper;
import com.imooc.trading_system.service.RouterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.trading_system.utils.JsonData;
import com.imooc.trading_system.vo.router.RouterListRespVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Feng zhaoxi
 * @since 2022-05-01
 */
@Service
public class RouterServiceImpl implements RouterService {
    @Resource
    private RouterMapper routerMapper;

    /**
     * 获取路由列表
     *
     * @return
     */
    @Override
    public JsonData getRouterList() {
        List<RouterDO> routerDOList = routerMapper.selectList(new QueryWrapper<>());
        List<RouterListRespVO> routerListRespVOS = routerDOList.stream().map(obj -> {
            RouterListRespVO routerListRespVO = new RouterListRespVO();
            BeanUtils.copyProperties(obj, routerListRespVO);
            return routerListRespVO;
        }).collect(Collectors.toList());
        return JsonData.buildSuccess(routerListRespVOS);
    }
}
